package com.ydd.widegt.story;

import android.content.Context;
import android.content.Intent;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ydd.R;
import com.ydd.model.story.StoryHeaderValue;
import com.ydd.moudle.home.AdBrowserActivity;
import com.ydd.util.glide.GlideManager;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by tao on 17-3-23.
 */

public class StoryDeailHeaderView extends RelativeLayout {
    private Context mContext;
    /**
     * UI
     */
    private RelativeLayout mRootView;
    private CircleImageView mPhotoView;
    private TextView mNameView;
    private TextView mDayView;
    private TextView mOldValueView;
    private TextView mNewValueView;
    private TextView mIntroductView;
    private TextView mFromView;
    private TextView mZanView;
    private TextView mScanView;
    private TextView mHotCommentView;
    /**
     * data
     */
    private StoryHeaderValue mData;

    public StoryDeailHeaderView(Context context, StoryHeaderValue headerValues) {
        super(context);
        this.mData = headerValues;
        this.mContext =context;
        init(null, 0);
    }

    public StoryDeailHeaderView(Context context, AttributeSet attrs, StoryHeaderValue headerValues) {
        super(context, attrs);
        this.mData = headerValues;
        init(attrs, 0);
    }

    public StoryDeailHeaderView(Context context, AttributeSet attrs, int defStyleAttr,
                                StoryHeaderValue headerValues) {
        super(context, attrs, defStyleAttr);
        this.mData = headerValues;
        init(attrs, defStyleAttr);
    }

    private void init(AttributeSet attrs, int defStyleAttr) {
        mRootView = (RelativeLayout) LayoutInflater.from(getContext()).inflate(R.layout.
                listview_course_comment_head_layout, this, true);
        mPhotoView = (CircleImageView) mRootView.findViewById(R.id.photo_view);
        mNameView = (TextView) mRootView.findViewById(R.id.name_view);
        mDayView = (TextView) mRootView.findViewById(R.id.day_view);
        mOldValueView = (TextView) mRootView.findViewById(R.id.old_value_view);
        mNewValueView = (TextView) mRootView.findViewById(R.id.new_value_view);
        mIntroductView = (TextView) mRootView.findViewById(R.id.introduct_view);
        mFromView = (TextView) mRootView.findViewById(R.id.from_view);

        mZanView = (TextView) mRootView.findViewById(R.id.zan_view);
        mScanView = (TextView) mRootView.findViewById(R.id.scan_view);
        mHotCommentView = (TextView) mRootView.findViewById(R.id.hot_comment_view);

        mRootView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, AdBrowserActivity.class);
                intent.putExtra(AdBrowserActivity.KEY_URL,mData.storyUrl);
                mContext.startActivity(intent);
            }
        });

        initData();
    }

    private void initData() {
        GlideManager.loadImageView(getContext(), mData.logo, mPhotoView);
        mNameView.setText(mData.name);
        mDayView.setText(mData.dayTime);
        mOldValueView.setText(mData.oldPrice);
        mOldValueView.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
        mNewValueView.setText(mData.newPrice);
        mIntroductView.setText(mData.text);
        mFromView.setText(mData.from);
        mZanView.setText(mData.zan);
        mScanView.setText(mData.scan);
        mHotCommentView.setText(mData.hotComment);

    }
}
